/* Copyright (C) 2010 Fredrique Samuels, fredriquesamuels@gmail.com */

/*
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "transform.h"

namespace tri {

TTransform::TTransform() : m_WireFrameMode(false), m_InverseTransform(false){
	m_Scale = tri::TVector(1, 1, 1);
}

TTransform::~TTransform(){}

void TTransform::setPosition(tri::TVector v){
	m_Pos = v;
}

void TTransform::setRotation(tri::TVector v){
	m_Rot = v;
}

void TTransform::setSize(tri::TVector v){
	m_Size = v;
}

void TTransform::setScale(tri::TVector v){
	m_Scale = v;
}

void TTransform::setPosition(float x, float y, float z){
    m_Pos.setValue(x, y, z);
}

void TTransform::setRotation(float x, float y, float z){
	m_Rot.setValue(x, y, z);
}

void TTransform::setSize(float x, float y, float z){
	m_Size.setValue(x, y, z);
}

void TTransform::setScale(float x, float y, float z){
	m_Scale.setValue(x, y, z);
}

void TTransform::setTargetPosition(tri::TVector v,float t){
	m_Pos.setTargetValue(&v[0],t);
}

void TTransform::setTargetRotation(tri::TVector v,float t){
	m_Rot.setTargetValue(&v[0],t);
}

void TTransform::setTargetSize(tri::TVector v,float t){
	m_Size.setTargetValue(&v[0],t);
}

void TTransform::setTargetScale(tri::TVector v,float t){
	m_Scale.setTargetValue(&v[0],t);
}


tri::TVector TTransform::getPosition(){
	return m_Pos.getValue();
}

tri::TVector TTransform::getRotation(){
	return m_Rot.getValue();
}

tri::TVector TTransform::getSize(){
	return m_Size.getValue();
}

tri::TVector TTransform::getScale(){
	return m_Scale.getValue();
}

tri::TMatrix TTransform::getModelMatrix(){
	return m_ModelMatrix;
}

//display settings
void TTransform::setWireFrameMode(bool b){
	m_WireFrameMode = b;
}

bool TTransform::isWireFrameMode(){
	return m_WireFrameMode;
}

void TTransform::setInverseTransform(bool b){
	m_InverseTransform = b;
}

void TTransform::applyTransform(){
	if(m_InverseTransform){
		graphics::rotate(m_Rot);
		graphics::translate(m_Pos);	    
	}else{
	    graphics::translate(m_Pos);
	    graphics::rotate(m_Rot);
	}
    glGetFloatv(GL_MODELVIEW_MATRIX,m_ModelMatrix.elements);
}

}//close namespace tri

